<!--#include file="classData.asp"-->
<!--#include file="classSort.asp"-->
<%
Response.Buffer = True 
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache" 
Response.AddHeader "Pragma", "No-Cache"

	tstate = 0

	cps1 = Request.Cookies("CupPlanState")
	cps2 = Request.Cookies("CupPlanState2")

	If cps1 <> "" Then

	  Response.Cookies("CupPlanState") = ""
	  Response.Cookies("CupPlanState2") = ""
	  
	  tstate = 1
	
	End If

	If tstate = 1 Then

'	GroupId = CInt(Request.QueryString("CurrentGroup"))
'	HomeId = CInt(Request.QueryString("maid"))
'	AwayId = CInt(Request.QueryString("mbid"))
'	btype = Request.QueryString("btype")
'	HomeScore = CInt(Request.QueryString("R1F"))
'	AwayScore = CInt(Request.QueryString("R1S"))
	'HomePoint = CInt(Request.QueryString("R1FD"))
	'AwayPoint = CInt(Request.QueryString("R1SD"))
	cpid = CInt(Request.QueryString("cpid"))
	maid = CInt(Request.QueryString("maid"))
	HomeScore = CInt(Request.QueryString("R1F"))
	AwayScore = CInt(Request.QueryString("R1S"))
	

	set HuaObj = new sysData
	HuaObj.sqlConnOpen()

	set SystemRds=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery SystemRds,"sysVar",QueryStr,0," VarId = 1"
	
	CurrentSeason = SystemRds("CurrentSeason")

	SystemRds.Close

	set GroupRds=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery GroupRds,"AreaCup",QueryStr,0," SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND ManagerId ="&maid
	
	CurrentGroup = GroupRds("CurrentGroup")

	GroupRds.Close
	
	set PlanRds=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery PlanRds,"CupPlan",QueryStr,0," CPId ="&cpid

	HomeId = PlanRds("HomeId")
	AwayId = PlanRds("AwayId")
	
	PlanRds.Close

	set LockRds=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery LockRds,"sysLeagueLock",QueryStr,0," 1=1"
	
	tNum = LockRds.RecordCount
		
	LockRds.Close

	If tNum = 0 Then
	
	InsertSql = "INSERT INTO sysLeagueLock VALUES("&maid&",getdate())"
	HuaObj.SCommand(InsertSql)
	
	End If

	set LockRdsB=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery LockRdsB,"sysLeagueLock",QueryStr,0," 1=1 ORDER BY OpDate DESC"
	
	tmid = LockRdsB("ManagerId")
		
	LockRdsB.Close

	If tmid = Cint(maid) Then

	HuaObj.p_DbConnection.BeginTrans
	on error resume next

	If HomeScore  > AwayScore Then
	
		HScore = 3
		AScore = 0
		HWinNum = 1
		HLostNum = 0
		tHDrawNum = 0
		AWinNum = 0
		ALostNum = 1
		ADrawNum = 0
	
	ElseIf HomeScore  < AwayScore Then
	
		HScore = 0
		AScore = 3
		HWinNum = 0
		HLostNum = 1
		tHDrawNum = 0
		AWinNum = 1
		ALostNum = 0
		ADrawNum = 0
	
	ElseIf HomeScore  = AwayScore Then
		
		HScore = 1
		AScore = 1
		HWinNum = 0
		HLostNum = 0
		tHDrawNum = 1
		AWinNum = 0
		ALostNum = 0
		ADrawNum = 1
		
	End If

	'更新主场
	InsertSql = "UPDATE AreaCup SET Score = Score + "&HScore&",Goal = Goal + "&HomeScore&",Fumble = Fumble + "&AwayScore&",GoalDif = GoalDif + ("&(HomeScore-AwayScore)&"),TotalRound = TotalRound + 1,WinNum = WinNum + "&HWinNum&",LostNum = LostNum + "&HLostNum&",DrawNum = DrawNum + "&tHDrawNum&" WHERE SeasonNum ="&CurrentSeason&" AND CupLevel = 5 AND ManagerId = "&HomeId
	HuaObj.SCommand(InsertSql)

	'更新客场
	InsertSql = "UPDATE AreaCup SET Score = Score + "&AScore&",Goal = Goal + "&AwayScore&",Fumble = Fumble + "&HomeScore&",GoalDif = GoalDif + ("&(AwayScore-HomeScore)&"),TotalRound = TotalRound + 1,WinNum = WinNum + "&AWinNum&",LostNum = LostNum + "&ALostNum&",DrawNum = DrawNum + "&ADrawNum&" WHERE SeasonNum ="&CurrentSeason&" AND CupLevel = 5 AND ManagerId = "&AwayId
	HuaObj.SCommand(InsertSql)
	

	'更新赛程表
	InsertSql = "UPDATE CupPlan SET IfDone = 2,HomeScore = "&HomeScore&",AwayScore = "&AwayScore&",HomePoint = "&maid&",MarkDate = '"&Date&"' WHERE CPId ="&cpid
	HuaObj.SCommand(InsertSql)

	InsertSql = "DELETE FROM sysLeagueLock"
	HuaObj.SCommand(InsertSql)


'	set UserRds=server.CreateObject("ADODB.recordset")
'	HuaObj.DbQuery UserRds,"ClubInfo",QueryStr,0," ManagerId = "&HomeId
'	
'	HomeClubId = UserRds("ClubId")
'
'	UserRds.Close
'	
'	set UserBRds=server.CreateObject("ADODB.recordset")
'	HuaObj.DbQuery UserBRds,"ClubInfo",QueryStr,0," ManagerId = "&AwayId
'	
'	AwayClubId = UserBRds("ClubId")
'
'	UserBRds.Close

'	HuaObj.p_DbConnection.BeginTrans
'	on error resume next


'	if (HomeScore + HomePoint) > (AwayScore + AwayPoint) then
'
'	  InsertSql = "UPDATE AreaCup SET IfDone = 1,Score = 3,Goal = "&HomeScore&",Fumble = "&AwayScore&",GoalDif = "&(HomeScore-AwayScore)&",TotalRound = 1,WinNum = 1,Ranking = 1 WHERE ManagerId ="&HomeId&" AND SeasonNum = "&CurrentSeason&" AND CupLevel = 6"
'	  HuaObj.SCommand(InsertSql)
'	  'Response.Write(InsertSql)
'	  
'	  InsertSql = "UPDATE AreaCup SET IfDone = 1,Score = 0,Goal = "&AwayScore&",Fumble = "&HomeScore&",GoalDif = "&(AwayScore-HomeScore)&",TotalRound = 1,LostNum = 1,Ranking = 2 WHERE ManagerId ="&AwayId&" AND SeasonNum = "&CurrentSeason&" AND CupLevel = 6"
'	  HuaObj.SCommand(InsertSql)
'	  'Response.Write(InsertSql)
'	  
'	  
'	  
'	  InsertSql = "UPDATE AreaCup SET ManagerId ="&HomeId&",ClubId = "&HomeClubId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND ManagerId = "&(92000+GroupId)
'	  HuaObj.SCommand(InsertSql)
'	  
'	  InsertSql = "UPDATE CupPlan SET HomeId ="&HomeId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND HomeId = "&(92000+GroupId)
'	  HuaObj.SCommand(InsertSql)
'	  
'	  InsertSql = "UPDATE CupPlan SET AwayId ="&HomeId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND AwayId = "&(92000+GroupId)
'	  HuaObj.SCommand(InsertSql)
'
'	else
'	
'	  InsertSql = "UPDATE AreaCup SET IfDone = 1,Score = 0,Goal = "&HomeScore&",Fumble = "&AwayScore&",GoalDif = "&(HomeScore-AwayScore)&",TotalRound = 1, LostNum= 1,Ranking = 2 WHERE ManagerId ="&HomeId&" AND SeasonNum = "&CurrentSeason&" AND CupLevel = 6"
'	  HuaObj.SCommand(InsertSql)
'	  'Response.Write(InsertSql)
'	  
'	  InsertSql = "UPDATE AreaCup SET IfDone = 1,Score = 3,Goal = "&AwayScore&",Fumble = "&HomeScore&",GoalDif = "&(AwayScore-HomeScore)&",TotalRound = 1, WinNum= 1,Ranking = 1 WHERE ManagerId ="&AwayId&" AND SeasonNum = "&CurrentSeason&" AND CupLevel = 6"
'	  HuaObj.SCommand(InsertSql)
'	  'Response.Write(InsertSql)
'	  
'	  
'	  InsertSql = "UPDATE AreaCup SET ManagerId ="&AwayId&",ClubId = "&AwayClubId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND ManagerId = "&(92000+GroupId)
'	  HuaObj.SCommand(InsertSql)
'	  
'	  InsertSql = "UPDATE CupPlan SET HomeId ="&AwayId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND HomeId = "&(92000+GroupId)
'	  HuaObj.SCommand(InsertSql)
'	  
'	  InsertSql = "UPDATE CupPlan SET AwayId ="&AwayId&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 5 AND AwayId = "&(92000+GroupId)
'	  HuaObj.SCommand(InsertSql)
'	
'	end if
'	
'	InsertSql = "UPDATE CupPlan SET HomeScore = "&HomeScore&",HomePoint = "&HomePoint&",AwayScore = "&AwayScore&",AwayPoint = "&AwayPoint&",IfDone = 1,MarkDate = '"&Date&"' WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = 6 AND HomeId = "&HomeId&" AND AwayId = "&AwayId
'	HuaObj.SCommand(InsertSql)


	response.ContentType="text/xml"	
	Response.Write("<?xml version=""1.0"" encoding=""gb2312""?>"&vbcrlf)
	Response.Write("<xml>"&vbcrlf)


	if err.number =0 then  
    	HuaObj.p_DbConnection.CommitTrans  '如果没有conn错误，则执行事务提交
		call SortSameScore(CurrentSeason,3,CurrentGroup,HomeId)
		call SortSameScore(CurrentSeason,3,CurrentGroup,AwayId)
		call SortScore(CurrentSeason,3,CurrentGroup)
		Response.Write("<Shi ShiId = ""1"">"&vbcrlf)
		Response.Write("</Shi>"&vbcrlf)
	else 
    	HuaObj.p_DbConnection.RollbackTrans '否则回滚
		Response.Write("<Shi ShiId = ""0"">"&vbcrlf)
		Response.Write("</Shi>"&vbcrlf)
	end if

	Else
	
		InsertSql = "DELETE FROM sysLeagueLock WHERE OpDate < DATEADD(n,-3,'"&Date&" "&Time&"')"
		HuaObj.SCommand(InsertSql)
	
		Response.Write("<Shi ShiId = ""2"">"&vbcrlf)
		Response.Write("</Shi>"&vbcrlf)

	End If

	Response.Write("</xml>"&vbcrlf)

	
	HuaObj.sqlConnClose()

	End If
%>
